#!/bin/bash
ClangbuilderDir=$(cd `dirname $0`; pwd)
if [[ ! -f "$ClangbuilderDir/branch" ]]; then
  Branch="release_50"
else
  source "$ClangbuilderDir/branch"
fi
echo "Update LLVM branch: $Branch now"


function Restore-Repositories(){
  pushd $PWD
  echo "fetch $1 $2"
  if [ -d "$1/$2/.svn" ]; then
    cd "$1/$2"
    svn cleanup .
    svn up .
  else
    cd "$1"
    svn co $3 $2
  fi
  echo "ClangBuilder checkout $2 done."
  popd
}


Restore-Repositories "$ClangbuilderDir" "$Branch" "http://llvm.org/svn/llvm-project/llvm/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/tools" clang "http://llvm.org/svn/llvm-project/cfe/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/tools" lld "http://llvm.org/svn/llvm-project/lld/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/tools" lldb "http://llvm.org/svn/llvm-project/lldb/branches/$Branch"
#Restore-Repositories "$ClangbuilderDir/llvm/tools" llgo "http://llvm.org/svn/llvm-project/llgo/$Branch
Restore-Repositories "$ClangbuilderDir/$Branch/tools/clang/tools" extra "http://llvm.org/svn/llvm-project/clang-tools-extra/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/projects" compiler-rt "http://llvm.org/svn/llvm-project/compiler-rt/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/projects" libcxx "http://llvm.org/svn/llvm-project/libcxx/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/projects" libcxxabi "http://llvm.org/svn/llvm-project/libcxxabi/branches/$Branch"
Restore-Repositories "$ClangbuilderDir/$Branch/projects" openmp "http://llvm.org/svn/llvm-project/openmp/branches/$Branch"
